package com.bookmanagement.mapper;

import com.bookmanagement.entity.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

@Mapper
public interface UserMapper {

    @Select("select * from user where email = #{email}")
    User queryByEmail(String email);

    void insert(User newUser);

    @Update("update user set username = #{username}, avatar = #{avatar} where email = #{email}")
    void updateUserInfo(User user);

    @Update("update user set password = #{password} where email = #{email}")
    void updatePassword(User user);

    // 管理端：切换用户状态（禁用/启用）
    @Update("update user set status = #{status} where id = #{id}")
    void updateUserStatus(Integer id, Boolean status);

    // 管理端：重置用户密码
    @Update("update user set password = #{password} where id = #{id}")
    void resetPassword(Integer id, String password);

    // 管理端：根据ID查询用户
    @Select("select * from user where id = #{id}")
    User queryById(Integer id);

    // 管理端：获取所有用户（无论状态）
    @Select("select * from user order by create_at desc")
    List<User> getAllUsers();

}
